//
//  MainViewController.swift
//  CZWeiBo06
//
//  Created by Mac on 15/8/10.
//  Copyright (c) 2015年 Mac. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    
    

    @IBOutlet weak var mainTabBar: MainTabBar!
    
    override func viewDidLoad() {
        
        addViewControllers()
        
        self.mainTabBar.addBtn.addTarget(self as MainViewController, action: Selector("btnClick"), forControlEvents: UIControlEvents.TouchUpInside)
    }
    
    
    func btnClick() {
        
        println("Good")
    }
    
    
    ///添加所有的控制器
    func addViewControllers() {
        
        
        addViewController("Home", imageName: "tabbar_home", title: "首页")
        addViewController("Message", imageName: "tabbar_message_center", title: "消息")
        addViewController("Discorvery", imageName: "tabbar_discover", title: "发现")
        addViewController("Profile", imageName: "tabbar_profile", title: "我")

        
    }
    
    
    ///添加控制器
    func addViewController(sbName :String,imageName : String, title : String){
        
    
        UITabBar.appearance().tintColor = UIColor.orangeColor()
        let sb = UIStoryboard(name: sbName, bundle: nil)
        
        let nav = sb.instantiateInitialViewController() as! UINavigationController
        
        nav.tabBarItem.image = UIImage(named: imageName)
        nav.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")
        nav.topViewController.title = title
        self.addChildViewController(nav)
        
    }
}
